<?php
require_once("../../config/config.inc.php");

$sAction       = fn_getParam("strAction","");
$sEPID         = fn_getParam("strEPID","");
$sUserName     = fn_getParam("strUserName","");
$sPassword     = fn_getParam("strPassword","");
$sTrueName     = fn_getParam("strTrueName","");
$sPetName      = fn_getParam("strPetName","");
$sDepartment   = fn_getParam("strDepartment","");
$sTitle        = fn_getParam("strTitle","");
$sSex          = fn_getParam("strSex","");
$sBirthday     = fn_getParam("strBirthday","");
$sIDCard       = fn_getParam("strIDCard","");
$sAddress      = fn_getParam("strAddress","");
$sPostcode     = fn_getParam("strPostcode","");
$sTelephone    = fn_getParam("strTelephone","");
$sMobilephone  = fn_getParam("strMobilephone","");
$sQQNumb       = fn_getParam("strQQNumb","");
$sMSN          = fn_getParam("strMSN","");
$sEMail        = fn_getParam("strEMail","");
$sRemark       = fn_getParam("strRemark","");

$result = "";
$title  = "";
if ($sEPID != "") {
    $sql = "SELECT COUNT(1) FROM ".$TABLE_EP_USER;
    $sql.= " WHERE EPID=".$sEPID." AND USERNAME='".$sUserName."'";
    if ($DB->getFirstField($sql) > 0) {
        $result = "<font color='red'>该用户 ".$sUserName." 已经存在，不能重复添加；</font>";
        $title  = "<font color='red'>注册错误</font>";
    } else {
        $sql = "INSERT INTO $TABLE_EP_USER(EPID,USERNAME,TRUENAME,PASSWD,PETNAME,DEPARTMENT,";
        $sql.= "TITLE,SEX,BIRTHDAY,IDCARD,HOMEADDRESS,POSTCODE,HOMEPHONE,MOBILEPHONE,QQNUMB,";
        $sql.= "MSN,EMAIL,RIGHTLEVEL,REGDATE,REMARK) ";
        $sql.= "VALUES('".$sEPID."','".$sUserName."','".$sTrueName."',md5('".$sPassword."'),'".$sPetName."','";
        $sql.= $sDepartment."','".$sTitle."','".$sSex."','".$sBirthday."','".$sIDCard."','".$sAddress."','";
        $sql.= $sPostcode."','".$sTelephone."','".$sMobilephone."','".$sQQNumb."','".$sMSN."','";
        $sql.= $sEMail."','".($sAction==ACTION_ENTERPRISE?'admin':'user')."',now(),'".$sRemark."')";
        $DB->query($sql);
        
        if ($sAction==ACTION_ENTERPRISE) {
            $title = '完成企业及用户注册';
        } else {
            $title = '完成个人用户注册';
        }
    }
} else {
    $result = "<font color='red'>注册错误</font>";
    $title  = $result;
}

$SM->assign("result",$result);
$SM->assign("title" ,$title);

$SM->display("member/regUserAction.html");

?>
